package 面试;

import 面试.单例模式.CountyEnum;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {

    public static void main(String[] args) throws InterruptedException {
        CountDownLatch countDownLatch = new CountDownLatch(6);

//        for (int i = 1; i <= 6; i++) {
//            new Thread(() -> {
//                System.out.println(Thread.currentThread().getName() + "\t国，被灭！");
//                countDownLatch.countDown();
//            }, CountyEnum.forEachCountyEnum(i).getRetMessage()).start();
//        }

        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "\t秦国统一！");

        System.out.println();
        System.out.println(CountyEnum.ONE);
//        System.out.println(CountyEnum.ONE.getRetCode());
//        System.out.println(CountyEnum.ONE.getRetMessage());
    }


    public static void main01(String[] args) throws InterruptedException {

        CountDownLatch countDownLatch = new CountDownLatch(6);
        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println(Thread.currentThread().getName() + "上完自习，离开教室");
                countDownLatch.countDown();
            },String.valueOf(i)).start();
        }

        countDownLatch.await();
        System.out.println(Thread.currentThread().getName() + "++++++++++班长关门");
    }
}
